<template>
  <div>
    <Searchbar>
      <el-input style="margin-right: 10px" @change="getList" v-model="search.username" placeholder="请输入用户姓名"></el-input>
      <el-select style="margin-right: 10px" @change="onStatusChange" v-model="search.status" placeholder="请选择用户状态">
        <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>

      <el-button  @click="resetSearch" type="primary">重置</el-button>
      <el-button  @click="getList" type="primary">查询</el-button>

      <el-button class="search-btn" @click="onMulForbidden" type="info" icon="el-icon-lock">批量封停</el-button>
      <el-button class="search-btn" @click="onMulEnable" type="success" icon="el-icon-unlock">批量启用</el-button>
      <el-button class="search-btn" @click="onShowCreate" type="primary" icon="el-icon-plus">新建</el-button>
    </Searchbar>

<!--    <TableBar>-->
<!--      <el-button @click="onShowCreate" type="primary" icon="el-icon-plus">新建</el-button>-->
<!--      &lt;!&ndash; <el-button @click="onShowUpload" icon="el-icon-upload">批量上传</el-button> &ndash;&gt;-->
<!--      <el-button @click="onMulForbidden" icon="el-icon-lock">批量封停</el-button>-->
<!--      <el-button @click="onMulEnable" icon="el-icon-unlock">批量启用</el-button>-->
<!--    </TableBar>-->

    <el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%">
      <el-table-column fixed="left" type="selection" width="55"></el-table-column>
      <el-table-column fixed="left" type="index" label="序号" width="55"></el-table-column>
      <el-table-column prop="username" label="用户名" ></el-table-column>
      <el-table-column prop="phone" label="手机号" ></el-table-column>
<!--      <el-table-column prop="grade" label="班级" ></el-table-column>-->
      <el-table-column prop="statusLabel" label="状态" ></el-table-column>
      <el-table-column prop="create_time" label="注册时间" ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="onShowDetail(scope.row)"
            size="small"
            class="text-button"
            type="primary"
          >查看</el-button>
          <el-button @click="onShowEdit(scope.row)" type="primary" size="small" >编辑</el-button>
          <el-button
              v-if="scope.row.status == 1 "
            @click="onForbidden(scope.row)"
            size="small"
            type="info"
          >封停</el-button>
          <el-button
            v-else
            @click="onForbidden(scope.row)"
            size="small"
            type="success"
          >启用</el-button>
        </template>
        <!--            :class="scope.row.status == 1 ? 'text-warning' : 'text-button'"-->
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, sizes, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-sizes="page_sizes"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
    <EditStudent @afterSubmit="getList" @onClose="onHideEdit" :obj="editRow" :show="showEdit" />
    <MulUpload :temp="2" :type="4" @onClose="onHideUpload" :show="showUpload" />
  </div>
</template>
<script>
import EditStudent from "@/modals/EditStudent";
import MulUpload from "@/components/MulUpload";
import CreateFilter from "@/mixins/CreateFilter";
import showEditMixin from "@/mixins/showEditMixin";
import uploadMixin from "@/mixins/uploadMixin";
import pageMixin from "@/mixins/pageMixin";
import { studentModel } from "@/api/admin_models";
import Searchbar from "@/components/Searchbar";
import TableBar from "@/components/TableBar";
import blockMixin from '@/mixins/blockMixin.js'
export default {
  mixins: [CreateFilter, showEditMixin, uploadMixin, pageMixin, blockMixin],
  components: { EditStudent, MulUpload, Searchbar, TableBar },
  data() {
    return {
      showEditStudent: false,
      tableData: [],
      total: 0,
      search: {
        userid: null,
        username: null,
        selectedschool_id: null,
        selectedcollege_id: null,
        selectedmajor_id: null,
        selectedclass_id: null,
        status: null,
        page: 1,
        page_size: 10
      }
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    batchBlockFun() {
      return studentModel.batchBlock;
    },
    onShowDetail(row) {
      this.$router.push('student/' + row.userid)
      console.log(row);
    },
    resetSearch() {
      this.search = {
        userid: null,
        username: null,
        selectedschool_id: null,
        selectedcollege_id: null,
        selectedmajor_id: null,
        selectedclass_id: null,
        status: null,
        page: 1,
      };
      this.selectedSchool = ''
      this.selectedCollege = ''
      this.selectedMajor =  ''
      this.selectedClass = ''
      this.getList();
    },
    getList() {
      studentModel.list(
        this.search,
        res => {
          this.total = res.total_records;
          this.tableData = res.data.map(v => {
            v.statusLabel = this.statusToLabel(v.status);
            return v;
          });
        },
        err => {
          console.log(err);
        }
      );
    }
  }
};
</script>
<style lang="scss">
</style>